1 <?php
2 session_start(); // Use session variable on this page. This function must put on the top of page.
3 if(!isset($_SESSION['username']) || $_SESSION['usertype'] !='admin'){ // if session variable "username" does not exist.
4 header("location:index.php?msg=Please%20login%20to%20access%20admin%20area%20!"); // Re-direct to index.php
5 }
6 else
7 {
8 include_once "db.php";
9 error_reporting (E_ALL ^ E_NOTICE);
10
11 ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
12 "http://www.w3.org/TR/html4/loose.dtd">
13 <html>
14 <head>
15 <title>Welcome to Stock Management System !</title>
16 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
17 <link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css" media="screen" title="no title" charset="utf-8" />
18 <link rel="stylesheet" href="css/template.css" type="text/css" media="screen" title="no title" charset="utf-8" />
19 <script src="js/jquery.min.js" type="text/javascript"></script>
20 <script type="text/javascript" src="jquery.date_input.js"></script>
21 <link rel="stylesheet" href="date_input.css" type="text/css">
22 <script type="text/javascript">$(function() {
23 $("#datefield").date_input();
24 });</script>
25
26 <script type='text/javascript' src='lib/jquery.bgiframe.min.js'></script>
27 <script type='text/javascript' src='lib/jquery.ajaxQueue.js'></script>
28 <script type='text/javascript' src='lib/thickbox-compressed.js'></script>
29 <script type='text/javascript' src='jquery.autocomplete.js'></script>
30 <script type='text/javascript' src='localdata.js'></script>
31
32 <link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
33 <link rel="stylesheet" type="text/css" href="lib/thickbox.css" />
34
35 <script type="text/javascript">
36 $().ready(function() {
37
38 function log(event, data, formatted) {
39 $("<li>").html( !data ? "No match!" : "Selected: " + formatted).appendTo("#result");
40 }
41
42 function formatItem(row) {
43 return row[0] + " (<strong>id: " + row[1] + "</strong>)";
44 }
45 function formatResult(row) {
46 return row[0].replace(/(<.+?>)/gi, '');
47 }
48
49
50
51 $("#singleBirdRemote").autocomplete("stock.php", {
52 width: 160,
53 autoFill: true,
54 selectFirst: false
55 });
56 $("#supplier").autocomplete("supplier1.php", {
57 width: 160,
58 autoFill: true,
59 selectFirst: false
60 });
61 $("#category").autocomplete("category.php", {
62 width: 160,
63 autoFill: true,
64 selectFirst: false
65 });
66 $("#uom").autocomplete("uom.php", {
67 width: 160,
68 autoFill: true,
69 selectFirst: false
70 });
71
72
73 $("#clear").click(function() {
74 $(":input").unautocomplete();
75 });
76 });
77
78
79 </script>
80
81 <script src="js/jquery.validationEngine-en.js" type="text/javascript"></script>
82 <script src="js/jquery.validationEngine.js" type="text/javascript"></script>
83 <script src="js/jquery.hotkeys-0.7.9.js"></script>
84 <!-- AJAX SUCCESS TEST FONCTION
85 <script>function callSuccessFunction(){alert("success executed")}
86 function callFailFunction(){alert("fail executed")}
87 </script>
88 -->
89
90 <script>
91
92
93
94
95
96 $(document).ready(function() {
97 // SUCCESS AJAX CALL, replace "success: false," by: success : function() { callSuccessFunction() },
98 $("#singleBirdRemote").focus();
99 $("#singleBirdRemote").blur(function()
100 {
101
102 $.post('check_stock_details.php', {stock_name: $(this).val() },
103 function(data){
104
105 // if(data=='no') //if username not avaiable
106 // {
107 // $("#category").focus();
108 // }
109 $("#category").val(data.category);
110 $("#supplier").val(data.supplier);
111 $("#buyingrate").val(data.buyingrate);
112 $("#sellingrate").val(data.sellingprice);
113 $("#uom").val(data.uom);
114 $("#available").val(data.available);
115 $("#quantity").focus();
116 }, 'json');
117
118
119
120
121
122 });
123
124 $("#form1").validationEngine(),
125
126 jQuery(document).bind('keydown', 'Ctrl+s',function() {
127 $('#form1').submit();
128 return false;
129 });
130
131 jQuery(document).bind('keydown', 'Ctrl+r',function() {
132 $('#form1').reset();
133 return false;
134 });
135 jQuery(document).bind('keydown', 'Ctrl+a',function() {
136 window.location = "addstock.php";
137 return false;
138 });
139 jQuery(document).bind('keydown', 'Ctrl+0',function() {
140 window.location = "admin.php";
141 return false;
142 });
143 jQuery(document).bind('keydown', 'Ctrl+1',function() {
144 window.location = "add_purchase.php";
145 return false;
146 });
147 jQuery(document).bind('keydown', 'Ctrl+2',function() {
148 window.location = "add_stock_sales.php";
149 return false;
150 });
151 jQuery(document).bind('keydown', 'Ctrl+3',function() {
152 window.location = "add_stock_details.php";
153 return false;
154 });
155 jQuery(document).bind('keydown', 'Ctrl+4',function() {
156 window.location = "add_category.php";
157 return false;
158 });
159 jQuery(document).bind('keydown', 'Ctrl+5',function() {
160 window.location = "add_supplier_details.php";
161 return false;
162 });
163 jQuery(document).bind('keydown', 'Ctrl+6',function() {
164 window.location = "add_customer_details.php";
165 return false;
166 });
167 jQuery(document).bind('keydown', 'Ctrl+7',function() {
168 window.location = "view_stock_entries.php";
169 return false;
170 });
171 jQuery(document).bind('keydown', 'Ctrl+8',function() {
172 window.location = "view_stock_sales.php";
173 return false;
174 });
175 jQuery(document).bind('keydown', 'Ctrl+9',function() {
176 window.location = "view_stock_details.php";
177 return false;
178 });
179 //$.validationEngine.loadValidation("#date")
180 //alert($("#formID").validationEngine({returnIsValid:true}))
181 //$.validationEngine.buildPrompt("#date","This is an example","error") // Exterior prompt build example // input prompt close example
182 //$.validationEngine.closePrompt(".formError",true) // CLOSE ALL OPEN PROMPTS
183 });
184 </script>
185 <style type="text/css">
186 <!--
187 body {
188 margin-left: 0px;
189 margin-top: 0px;
190 margin-right: 0px;
191 margin-bottom: 0px;
192 background-color: #FFFFFF;
193 }
194
195 *{
196 padding: 0px;
197 margin: 0px;
198 }
199 #vertmenu {
200 font-family: Verdana, Arial, Helvetica, sans-serif;
201 font-size: 100%;
202 width: 160px;
203 padding: 0px;
204 margin: 0px;
205 }
206
207 #vertmenu h1 {
208 display: block;
209 background-color:#FF9900;
210 font-size: 90%;
211 padding: 3px 0 5px 3px;
212 border: 1px solid #000000;
213 color: #333333;
214 margin: 0px;
215 width:159px;
216 }
217
218 #vertmenu ul {
219 list-style: none;
220 margin: 0px;
221 padding: 0px;
222 border: none;
223 }
224 #vertmenu ul li {
225 margin: 0px;
226 padding: 0px;
227 }
228 #vertmenu ul li a {
229 font-size: 80%;
230 display: block;
231 border-bottom: 1px dashed #C39C4E;
232 padding: 5px 0px 2px 4px;
233 text-decoration: none;
234 color: #666666;
235 width:160px;
236 }
237
238 #vertmenu ul li a:hover, #vertmenu ul li a:focus {
239 color: #000000;
240 background-color: #eeeeee;
241 }
242 .style1 {color: #000000}
243
244 -->
245 </style>
246 </head>
247
248 <body>
249 <table width="100%" border="0" cellspacing="0" cellpadding="0">
250 <tr>
251 <td align="center" valign="top"><table width="960" border="0" cellspacing="0" cellpadding="0">
252 <tr>
253 <td><table width="960" border="0" cellpadding="0" cellspacing="0" bgcolor="#ECECEC">
254 <tr>
255 <td height="90" align="left" valign="top"><img src="images/topbanner.jpg" width="960" height="82"></td>
256 </tr>
257 <tr>
258 <td height="800" align="left" valign="top"><table width="960" border="0" cellpadding="0" cellspacing="0" bgcolor="#ECECEC">
259 <tr>
260 <td width="130" align="left" valign="top">
261
262 <br>
263
264 <strong>Welcome <font color="#3399FF"><?php echo $_SESSION['username']; ?> !</font></strong><br> <br>
265 <table width="100%" border="0" cellspacing="0" cellpadding="0">
266 <tr>
267 <td align="center"><a href="admin.php"><img src="images/home.png" width="130" height="99" border="0"></a></td>
268 </tr>
269 <tr>
270 <td align="center"> </td>
271 </tr>
272 <tr>
273 <td align="center"><a href="add_purchase.php"><img src="images/purchase.png" width="130" height="124" border="0"></a></td>
274 </tr>
275 <tr>
276 <td align="center"> </td>
277 </tr>
278 <tr>
279 <td align="center"><a href="add_stock_sales.php"><img src="images/sales.png" width="146" height="111" border="0"></a></td>
280 </tr>
281 <tr>
282 <td align="center"> </td>
283 </tr>
284 <tr>
285 <td align="center"><a href="report.php"><img src="images/reports.png" width="131" height="142" border="0"></a></td>
286 </tr>
287 <tr>
288 <td align="center"> </td>
289 </tr>
290 <tr>
291 <td align="center"> </td>
292 </tr>
293 <tr>
294 <td align="center"> </td>
295 </tr>
296 </table>
297
298
299
300
301
302 </td> <td height="500" align="center" valign="top">
303 <table width="100%" border="0" cellspacing="0" cellpadding="0">
304 <tr>
305 <td><a href="add_stock_details.php"><img src="images/addstockdetails.png" width="67" height="62" border="0"></a></td>
306 <td><a href="add_supplier_details.php"><img src="images/supplier.png" width="67" height="54" border="0"></a></td>
307 <td><a href="add_customer_details.php"><img src="images/customer.png" width="67" height="54" border="0"></a></td>
308 <td><a href="add_category.php"><img src="images/categories.png" width="67" height="54" border="0"></a></td>
309 <td><a href="view_stock_sales.php"><img src="images/vsales.png" width="67" height="54" border="0"></a></td>
310 <td><a href="view_stock_entries.php"><img src="images/vpurchase.png" width="67" height="54" border="0"></a></td>
311 <td><a href="view_stock_details.php"><img src="images/stockdetails.png" width="67" height="54" border="0"></a></td>
312 <td><a href="view_stock_availability.php"><img src="images/savail.png" width="67" height="54" border="0"></a></td>
313 <td align="left" valign="top"><a href="view_customer_details.php"><img src="images/customers.png" width="94" height="22" border="0"></a><br> <a href="view_supplier_details.php"><img src="images/suppliers.png" width="94" height="22" border="0"></a><br>
314 <a href="view_payments.php"><img src="images/payments.png" width="94" height="22" border="0"></a></td>
315 <td align="left" valign="top"><a href="view_stock_sales_payments.php"><img src="images/outstanding.png" width="94" height="22" border="0"></a><br> <a href="view_stock_entries_payments.php"><img src="images/pendings.png" width="94" height="22" border="0"></a><br>
316 <a href="logout.php"><img src="images/logout.png" width="94" height="22" border="0"></a></td>
317 </tr>
318 </table>
319 <?php
320 if(isset($_POST['name']))
321
322 {
323 $sid=$_POST['id'];
324 $pid=$_POST['pid'];
325 $name=mysql_real_escape_string($_POST['name']);
326 $category=mysql_real_escape_string($_POST['category']);
327 $buyingrate=mysql_real_escape_string($_POST['buyingrate']);
328 $sellingrate=mysql_real_escape_string($_POST['sellingrate']);
329 $suplier=mysql_real_escape_string($_POST['suplier']);
330
331 $quantity=mysql_real_escape_string($_POST['quantity']);
332
333 $selected_date=$_POST['date'];
334 $selected_date=strtotime( $selected_date );
335 $mysqldate = date('Y-m-d H:i:s', $selected_date );
336 $username = $_SESSION['username'];
337
338 $total = $db->queryUniqueValue("SELECT quantity FROM stock_avail WHERE name='$name'");
339 $previous = $db->queryUniqueValue("SELECT quantity FROM stock_entries WHERE stock_id='$sid'");
340 $opening_stock = $db->queryUniqueValue("SELECT quantity FROM stock_entries WHERE stock_id='$sid'");
341
342
343
344 if($quantity < $previous)
345 {
346
347 $difference = $previous - $quantity;
348 $total = $total - $difference;
349
350 $result=$db->query("SELECT * FROM stock_entries where id >= $pid");
351 while ($line1 = $db->fetchNextObject($result)) {
352
353 $osd=$line1->opening_stock - $difference;
354 $csd=$line1->closing_stock - $difference;
355 $cid=$line1->id;
356
357 $db->execute("UPDATE stock_entries SET opening_stock=".$osd.",closing_stock=".$csd." WHERE id=$cid");
358
359 }
360
361
362 }
363 if($quantity > $previous)
364 {
365 $difference = $quantity - $previous;
366 $total = $total + $difference;
367
368 $result=$db->query("SELECT * FROM stock_entries where id >= $pid");
369 while ($line2 = $db->fetchNextObject($result)) {
370 $osd=$line2->opening_stock + $difference;
371 $csd=$line2->closing_stock + $difference;
372 $cid=$line2->id;
373
374 $db->execute("UPDATE stock_entries SET opening_stock=".$osd.",closing_stock=".$csd." WHERE id=$cid");
375
376 }
377 }
378
379
380
381 $db->execute("UPDATE stock_avail SET quantity=$total WHERE name='$name'");
382
383 $db->execute("UPDATE stock_entries SET stock_name='$name',stock_supplier_name='$suplier',category='$category',quantity=$quantity,company_price=$buyingrate,selling_price=$sellingrate,date='$mysqldate',username='$username' WHERE stock_id='$sid'");
384
385 echo "<br><font color=green size=+1 > [$name] Stock Entry Updated !</font>" ;
386
387 }
388
389
390 if(isset($_GET['id']))
391 {
392
393 $id=$_GET['id'];
394
395
396 $line = $db->queryUniqueObject("SELECT * FROM stock_entries WHERE id=$id");
397 ?>
398
399 <br>
400 <br>
401
402
403 <form name="form1" method="post" id="form1" action="">
404 <input name="pid" type="hidden" value="<?php echo $_GET['id']; ?>">
405
406 <p align="center"><strong>Update Stock Entry </strong> - Add New ( Control +A)</p>
407 <table width="600" border="0" cellspacing="0" cellpadding="0">
408 <tr>
409 <td width="150"> </td>
410 <td width="150"> </td>
411 <td width="150"> </td>
412 <td width="150"> </td>
413 </tr>
414 <tr>
415 <td width="150"> </td>
416 <td width="150"> </td>
417 <td width="150"> </td>
418 <td width="150"> </td>
419 </tr>
420 <tr>
421 <td width="150">ID</td>
422 <td width="150"><input name="id" type="text" id="id" readonly="" value="<?php echo $line->stock_id;?>"></td>
423 <td width="150">Date</td>
424
425 <td width="150"> <input type="text" id="datefield" name="date" class="date_input" value="<?php
426 $mysqldate=$line->date;
427 $phpdate = strtotime( $mysqldate );
428 $phpdate = date("d-m-Y",$phpdate);
429 echo $phpdate;
430 ?>"></td>
431 </tr>
432 <tr>
433 <td width="150"> </td>
434 <td width="150"> </td>
435 <td width="150"> </td>
436 <td width="150"> </td>
437 </tr>
438 <tr>
439 <td width="150"><strong>Name</strong></td>
440 <td width="150"><input name="name" type="text" id="singleBirdRemote" class="validate[required,length[0,100]] text-input" value="<?php echo $line->stock_name ;?>"></td>
441 <td width="150">Category</td>
442 <td width="150"><input name="category" id="category" type="text" value="<?php echo $line->category ;?>" ></td>
443 </tr>
444 <tr>
445 <td width="150"> </td>
446 <td width="150"> </td>
447 <td width="150"> </td>
448 <td width="150"> </td>
449 </tr>
450 <tr>
451 <td width="150">Supplier</td>
452 <td width="150"><input name="suplier" type="text" id="supplier" class="validate[optional,length[0,100]] text-input" value="<?php echo $line->stock_supplier_name ;?>"></td>
453 <td width="150"> </td>
454 <td width="150"> </td>
455 </tr>
456 <tr>
457 <td> </td>
458 <td> </td>
459 <td> </td>
460 <td> </td>
461 </tr>
462 <tr>
463 <td>Buying Rate</td>
464 <td><input name="buyingrate" type="text" id="buyingrate" class="validate[required,custom[onlyNumber],lengthCheck[6]] text-input" value="<?php echo $line->company_price ;?>"></td>
465 <td>Selling Rate </td>
466 <td><input name="sellingrate" type="text" id="sellingrate" class="validate[required,custom[onlyNumber],lengthCheck[6]] text-input" value="<?php echo $line->selling_price ;?>"></td>
467 </tr>
468 <tr>
469 <td> </td>
470 <td> </td>
471 <td> </td>
472 <td> </td>
473 </tr>
474 <tr>
475 <td><strong>Quantity</strong></td>
476 <td><input name="quantity" type="text" id="quantity" class="validate[required,custom[onlyNumber],lengthCheck[6]] text-input" value="<?php echo $line->quantity ;?>" ></td>
477 <td>Available Quantity </td>
478 <td><input name="available" type="text" id="available" value="<?php
479
480 $availquantity = $db->queryUniqueValue("SELECT quantity FROM stock_avail WHERE name='".$line->stock_name."'");
481 echo $availquantity;?>" readonly=""></td>
482 </tr>
483 <tr>
484 <td> </td>
485 <td> </td>
486 <td> </td>
487 <td> </td>
488 </tr>
489 <tr>
490 <td> </td>
491 <td> </td>
492 <td> </td>
493 <td> </td>
494 </tr>
495 <tr>
496 <td> </td>
497 <td> </td>
498 <td> </td>
499 <td> </td>
500 </tr>
501 <tr>
502 <td align="right"> </td>
503 <td align="right"><input type="reset" name="Reset" value="Reset">
504 </td>
505 <td>
506 <input type="submit" name="Submit" value="Save"></td>
507 <td> </td>
508 </tr>
509 <tr>
510 <td align="center"> </td>
511 <td align="center"> (Control + R) </td>
512 <td align="left"> ( Control + S ) </td>
513 <td align="left"> </td>
514 </tr>
515 </table>
516 </form>
517
518
519 <?php
520 }
521 else
522 echo "Error in processing the stock Entry updation";
523 ?></td>
524 </tr>
525 </table>
526
527 </td>
528 </tr>
529 <tr>
530 <td height="30" align="center" bgcolor="#72C9F4"><span class="style1"><a href="http://www.pluskb.com">Developed by PlusKB Innovations</a></span></td>
531 </tr>
532 </table></td>
533 </tr>
534 </table></td>
535 </tr>
536 </table>
537
538 </body>
539 </html>
540 <?php
541 }
542 ?>